import Vue from "vue"
import Vuex from "vuex"
import { picUrl } from 'pack';
import VuexPersistence from 'vuex-persist'
const vuexLocal = new VuexPersistence({
    storage: window.sessionStorage,
    modules: ["d", "e","b","f"]
})

Vue.use(Vuex)
//图片地址
const moduleA = {
    //state:'http://oneshop.1bpcafe.cn/ecshop/img/',//咖啡馆临时服务器
    //   state:"http://ecshop.1bpmedia.cn/ecshop/img/",//生产环境图片路径
    //   state:"http://ecshoptest.ebj.ebjcloud.com/ecshop/img/",//测试环境图片路径
    state:picUrl(),
    mutations: {},
    actions: {}
}

const moduleB = {
    state: {
        title: "",
        cateId:"",//保存页面的地址页面id
        headerShow:true,
        shopShow:false,
        isRegisterPhone:false,                  //保存是否注册过手机号
    },
    mutations: {
        increment(state, newtitle) {
            state.title = newtitle;
            document.title = newtitle || '首页';
        },
        ifHeaderShow(state, headerState){
            state.headerShow = headerState;
        },
        ifShopShow(state,showState){
            state.shopShow = showState;
        },
        addCateId(state,newCate){
            state.cateId = newCate;
        },
        deleteCateId(state){
            state.cateId = '';
        },
        changeRegState(state,newState){
            state.isRegisterPhone = newState;
        }
    }
}

const moduleC = {
    state: {
        recruitScrollY: 0
    },
    getters: {
        recruitScrollY: state => state.recruitScrollY
    },
    mutations: {
        changeRecruitScrollY(state, recruitScrollY) {
            state.recruitScrollY = recruitScrollY
        }
    },
}

const moduleD = {
    state: {
        peoductlist: [],
        selctlist: [],
        seltotal: {},
        noselctarrs: [],
        noContentGoods:[],
    },
    mutations: {
        addShop(state, newlist) {
            state.peoductlist = newlist;
        },
        slectShop(state, newlist) {
            state.selctlist = newlist;
        },
        addtotal(state, newlist) {
            state.seltotal = newlist;
        },
        setno(state, newlist) {
            state.noselctarrs = newlist;
        },
        addContentGoods(state,newList){
            state.noContentGoods = newList;
        }
    },
}

const moduleE = {
    state: {
        myresult: {},
        mchtCouponList: [],
        cateNo: '',
        goodsInfo:[],
    },
    mutations: {
        resetaddress(state, newtitle) {
            state.myresult = newtitle
        },
        mchtCouponList(state, newtitle) {
            state.mchtCouponList = newtitle
        },
        cateNo(state, newtitle) {
            state.cateNo = newtitle
        },
        setGoodsInfo(state,newInfo){
            state.goodsInfo = [...newInfo];
        }
    }
}

const moduleF = {
    state:{
        followImg:'',
    },
    mutations:{
        setFollowImg(state,newFollow){
            state.followImg = newFollow;
        }
    }
}


export const store = new Vuex.Store({
    modules: {
        a: moduleA,
        b: moduleB,
        c: moduleC,
        d: moduleD,
        e: moduleE,
        f: moduleF,
    },
    plugins: [vuexLocal.plugin]
})
